package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.AssessmentMethod;
import com.hwadee.teachingprocessmanagementsystem.dao.AssessmentMethodDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.AssessmentMethodService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

import java.util.List;

/**
 * 考核方式表(AssessmentMethod)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:02
 */
@Service("assessmentMethodService")
public class AssessmentMethodServiceImpl implements AssessmentMethodService {
    @Resource
    private AssessmentMethodDao assessmentMethodDao;

    /**
     * 通过ID查询单条数据
     *
     * @param methodId 主键
     * @return 实例对象
     */
    @Override
    public AssessmentMethod queryById(Integer methodId) {
        return this.assessmentMethodDao.queryById(methodId);
    }

    /**
     * 分页查询
     *
     * @param assessmentMethod 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AssessmentMethod> queryByPage(AssessmentMethod assessmentMethod, PageRequest pageRequest) {
        long total = this.assessmentMethodDao.count(assessmentMethod);
        return new PageImpl<>(this.assessmentMethodDao.queryAllByLimit(assessmentMethod, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param assessmentMethod 实例对象
     * @return 实例对象
     */
    @Override
    public AssessmentMethod insert(AssessmentMethod assessmentMethod) {
        this.assessmentMethodDao.insert(assessmentMethod);
        return assessmentMethod;
    }

    /**
     * 修改数据
     *
     * @param assessmentMethod 实例对象
     * @return 实例对象
     */
    @Override
    public AssessmentMethod update(AssessmentMethod assessmentMethod) {
        this.assessmentMethodDao.update(assessmentMethod);
        return this.queryById(assessmentMethod.getMethodId());
    }

    /**
     * 通过主键删除数据
     *
     * @param methodId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer methodId) {
        return this.assessmentMethodDao.deleteById(methodId) > 0;
    }

    @Override
    public List<AssessmentMethod> queryAll() {
        return this.assessmentMethodDao.queryAll();
    }
}
